﻿using Pantry.DataAccess;
using Pantry.Entity;
using System.Data;

namespace Pantry.Business
{
    public class PremiseBus
    {
        private readonly PremiseDao _premiseDao;
        public PremiseBus()
        {
            _premiseDao = new PremiseDao();
        }
        public bool AddPremise(Premises premises)
        {
            return (_premiseDao.AddPremise(premises) > 0);
        }
        public bool UpdatePremise(Premises premises)
        {
            return (_premiseDao.UpdatePremise(premises) > 0);
        }
        public DataTable GetAllPremise()
        {
            return _premiseDao.GetAllPremise();
        }
        public DataTable GetPremiseById(int premiseId)
        {
            return _premiseDao.GetPremiseById(premiseId);
        }
        public DataTable GetPremiseByLocationType(string locationType)
        {
            return _premiseDao.GetPremiseByLocationType(locationType);
        }
        public bool CheckNameIsExists(string inputName,string compareName,bool isUpdateMode)
        {
            bool result;
            if(isUpdateMode)
            {
                if (inputName == compareName)
                {
                    result = false;
                }
                else
                {
                    result = (_premiseDao.CheckNameExists(inputName) > 0);
                }
            }
            else
            {
                result = (_premiseDao.CheckNameExists(inputName) > 0);
            }
            return result;
        }
    }
}
